package com.mofofa.maozy.components.dialog

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.mofofa.maozy.R
import com.mofofa.maozy.data.RevObjWalletListFcfa
import com.mofofa.maozy.extend.isMaozyLink

class FcfaRecheckWalletAdapter(private val itemList: List<RevObjWalletListFcfa>) :
    RecyclerView.Adapter<FcfaRecheckWalletAdapter.ViewHolder>() {

    private var mMaozyOnMaozyDialogMaozyListMaozyItemMaozyClickMaozyListener: (RevObjWalletListFcfa, Int) -> Unit =
        { listItem: RevObjWalletListFcfa, i: Int -> }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tv_wallet_mobile_list_no_delete_mobile: TextView =
            view.findViewById(R.id.tv_wallet_mobile_list_no_delete_mobile)
        val iv_wallet_mobile_list_no_delete_logo: ImageView =
            view.findViewById(R.id.iv_wallet_mobile_list_no_delete_logo)
        val tv_wallet_mobile_list_no_delete_name: TextView =
            view.findViewById(R.id.tv_wallet_mobile_list_no_delete_name)

    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): FcfaRecheckWalletAdapter.ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.view_maozy_adpter_wallet_mobile_no_delete_fcfa, parent, false)
        return ViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: FcfaRecheckWalletAdapter.ViewHolder,
        position: Int
    ) {
        val item: RevObjWalletListFcfa = itemList[position]
        holder.tv_wallet_mobile_list_no_delete_mobile.text = item.walletMobile
        holder.tv_wallet_mobile_list_no_delete_name.text = item.walletDesc

        if (item.walletLogo.toString().isMaozyLink()) {
            Glide.with(holder.iv_wallet_mobile_list_no_delete_logo.context).load(item.walletLogo)
                .into(holder.iv_wallet_mobile_list_no_delete_logo)
        }

        holder.tv_wallet_mobile_list_no_delete_name.setOnClickListener {
            mMaozyOnMaozyDialogMaozyListMaozyItemMaozyClickMaozyListener.invoke(item, position)
        }
    }

    override fun getItemCount(): Int {
        return itemList.size
    }

    fun setMaozyOnMaozyItemMaozyClickMaozyListener(listener: (RevObjWalletListFcfa, Int) -> Unit) {
        mMaozyOnMaozyDialogMaozyListMaozyItemMaozyClickMaozyListener = listener
    }
}